package edu.sctu.java.advanced.pattern.chain;

import java.util.ArrayList;
import java.util.List;

public class InterceptorChain {

    List<Interceptor> interceptorList;

    public InterceptorChain() {

        interceptorList = new ArrayList<>();
    }

    void addInterceptor(Interceptor interceptor) {
        this.interceptorList.add(interceptor);
    }

    Context execute(Context context) {

        for (Interceptor interceptor : this.interceptorList) {

            context = interceptor.handle(context);
        }

        return context;

    }
}
